import { getFormFields } from '@/utils/formUtils'
import type { FormFieldConfig } from '@/types/form'

// 表格列配置
export const tableColumns = [
  {
    title: 'ID',
    dataIndex: 'id',
  },
  {
    title: '產品類型',
    dataIndex: 'productCate',
    customRender: (data) => {
      if (data.value === 1) {
        return '安宮系列'
      } else if (data.value === 2) {
        return '本廠'
      } else if (data.value === 3) {
        return 'OEM'
      } else {
        return '未知'
      }
    },
    customCell:(record, rowIndex, column) => {
      // console.log('record',record)
      // console.log('rowIndex',rowIndex)
      // console.log('column',column)
    }

  },
  {
    title: '銷售額下限（>）',
    dataIndex: 'lowerLimit',
  },
  {
    title: '銷售額上限（≤）',
    dataIndex: 'upperLimit',
  },
  {
    title: '分成比例',
    dataIndex: 'shareRatio',
  },
  {
    title: '最後修改時間',
    dataIndex: 'updatedAt',
  },
  {
    title: '操作',
    key: 'action',
    align: 'center',
  },
]

//表單
export const FormField: Record<string, FormFieldConfig> = {
  productCate: {
    label: '產品類型',
    type: 'select',
    placeholder: '請選擇附加推廣產品類型',
    rules: [{ required: true, message: '請選擇附加推廣產品類型' }],
    options: [
      {label: '安宮系列',key:1},
      {label: '本廠',key:2},
      {label: 'OEM',key:3},
    ],
    // defaultValue: 1,
    disabled: (type:string) => {
      return type=='edit'
    },
  },
  salesRange: {
    label: '銷售額範圍',
    type: 'numberRange', //作用是將一個值斷言為字面量類型
    placeholder: '請輸入銷售額範圍',
    rules: [{ required: true, message: '請輸入銷售額範圍' }],
    tooltip: '格式說明：(下限不包含，上限包含，如10000表示≤10000)',
    addonBefore:'$'
  },
  shareRatio: {
    label: '分成比例',
    type: 'number', //作用是將一個值斷言為字面量類型
    placeholder: '請輸入分成比例',
    rules: [{ required: true, message: '請輸入分成比例', type: 'number' }],
    min:0,
    max:100,
    addonAfter:'%'
  },
}

// 創建表單字段
export const getCreteFieldConfig = async (fields?: string[]) => {
  return getFormFields(FormField, fields)
}

export const getEditFieldConfig = async(fields?: string[]) => {
  return getFormFields(FormField, fields)
}




